package com.sunyard.response;


import com.sunyard.constant.CommonConst;
import lombok.Data;

@Data
public class Response {
    /**
     * 返回码
     */
    private String respCode;

    /**
     * 返回详情
     */
    private String respMsg;

    /**
     * 返回实体
     */
    private Object transInfo;

    private static String SYSTEM_ERROR = "系统异常";
    //返回成功描述
    public static final String RET_SUCCESS_DESC = "调用成功";

    /**
     * MAC校验值
     */
    private String macValue;

    public Response(String code, String desc, Object transInfo) {
        this.respCode = code;
        this.respMsg = desc;
        this.transInfo = transInfo;

    }

    public Response(String respCode, String respMsg) {
        this.respCode = respCode;
        this.respMsg = respMsg;
    }

    public Response(String code, String desc, Object transInfo, String macValue) {
        this.respCode = code;
        this.respMsg = desc;
        this.transInfo = transInfo;
        this.macValue = macValue;
    }

    public static Response success(Object transInfo) {
        return new Response(CommonConst.RET_SUCCESS, Response.RET_SUCCESS_DESC, transInfo);
    }

    public static Response fail(String desc) {
        return new Response(CommonConst.RET_FAIL, desc);
    }

    public static Response error() {
        return new Response(CommonConst.RET_ERROR, SYSTEM_ERROR);
    }

    public Response() {
    }

    @Override
    public String toString() {
        return "Response{" +
                "respCode='" + respCode + '\'' +
                ", respMsg='" + respMsg + '\'' +
                ", transInfo=" + transInfo +
                ", macValue='" + macValue + '\'' +
                '}';
    }
}
